home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / www / cern / doc / www-talk.archive.Z / www-talk.archive / text0355.txt < prev    next >
Encoding:
Text File  |  1992-11-30  |  4.2 KB  |  147 lines

  1.  
  2. Here is a quickly hacked up Gateway from WWW to the University
  3. of Michigan Geography server.  It expects one argument, a 
  4. WWW doc id.  It ignores the "pathname", extracts the search words,
  5. then passes those to the server.  It does NOT parse the data
  6. returned by the server (that is an improvment yet to be done)
  7. but you can understand the output.
  8.  
  9. To use this, you would need to have an HTTP server running
  10. someplace where you can attach this gateway.  I can provide
  11. the very simple HTTP server I use here, but this subject
  12. is already documented in the WWW online documentation.
  13.  
  14. Best wishes
  15.  
  16. #!/usr/local/bin/perl
  17. # Gateway from WWW to the Geography server at U Michigan
  18. # Copyright 1992 Xerox.  All rights reserved.
  19. # This program is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. # Jim Davis, Nov 17 1992
  23.  
  24. # To do:
  25. # 1) Parse the returned info so as to display more neatly.
  26. #    (See documentation at end of file its format.)
  27. # 2) Handle case where multiple places match supplied name
  28. # 3) Handle case where no place matches supplied name.
  29.  
  30. # This expects one argument, a document ID.  The search keywords
  31. # are sent to the Geography server, the "pathname" is ignored.
  32. # e.g. /geography/ignored/whocares?ithaca,ny => ithaca,ny
  33. # As an extra bonus feature, if the first arg has no question marks
  34. # then the entire arg line is passed to the server.  This is
  35. # convenient when you call this from the shell rather than from WWW.
  36.  
  37. if ($#ARGV == -1) {
  38.  die "Usage: geography-gateway [WWW-DOCUMENT-ID | location]\
  39. An example WWW document id is /geography?washington,dc
  40. If calling from shell, omit the /geography? part.\nStopped";}
  41.  
  42. $usage =  "<ISINDEX>\n\
  43. <TITLE>Geography Server</TITLE>\n\
  44. <h2>Type geographic name in Index.</h2>\n\
  45. ";
  46.  
  47. # for debugging
  48. # print "<LISTING>\n";
  49. # print "ARGV =  $#ARGV\n";
  50. # for ($i = 0; $i < $#ARGV+1; $i++) {
  51. #   print "Arg $i is $ARGV[$i]\n";}
  52. # print "</LISTING>";
  53. # exit;
  54.  
  55.  
  56. @parts=split('/', $ARGV[0]);  # separate pathname from keywords.
  57. $last = $parts[$#parts];      # the last path component has keys
  58. $i=index($last,"?");          # are there any keywords in there?
  59. if ($i == -1)
  60.    {@keywords = @ARGV;}          # none, probably called from shell
  61.  else
  62.    {@keywords=split('\?', substr($last,$i));
  63.     $parts[$#parts] = substr($last,0,$i);}
  64.  
  65.  
  66. # if no keywords, tell user how to type them.
  67.  
  68. if ($#keywords == -1) {
  69.   print $usage;
  70.   exit;
  71.   };
  72.  
  73.  
  74. # debugging
  75. # print "<LISTING>\n
  76. # parts are @parts\n
  77. # keywords are @keywords\n
  78. # </LISTING>\n";
  79. # exit;
  80.  
  81. # otherwise contact the server
  82.  
  83. $host = "martini.eecs.umich.edu";
  84. $port = 3000;
  85.  
  86. $sockaddr = 'S n a4 x8';         # packing format
  87.  
  88. $hostname = `hostname`;          # where I am calling from
  89. chop($hostname);                 # get rid of trailing CR
  90. ($name, $aliases, $type, $len, $myaddr) = gethostbyname($hostname);
  91. $here = pack($sockaddr, 2, 0, $myaddr);
  92.  
  93. ($name, $aliases, $type, $len, $destaddr) = gethostbyname($host);
  94.  
  95. #print ("Name = ", $name ," " addr = ", $destaddr, "\n");
  96. if ($destaddr eq "") {die "No such host: $host. Stopped";}
  97.  
  98. $there= pack($sockaddr, 2, $port, $destaddr);
  99.  
  100. ($name, $aliases, $protocol) = getprotobyname('tcp');
  101. socket($S, 2, 1, $protocol) || die "socket: $!";
  102. bind ($S, $here) || die "bind: $!";
  103. connect ($S, $there) || die "connect: $!";
  104.  
  105.  
  106. select($S);
  107. $| = 1;           # force output
  108. print (@keywords ,"\n");
  109. print "quit\n";
  110. select(STDOUT);
  111. print "<LISTING>\n";
  112. while (<$S>) { print;}
  113. print "</LISTING>\n";
  114. select($S);
  115. exit;
  116.  
  117. # This is the format of info returned by the geo server.
  118. # in case you decide you want to parse it.
  119.  
  120. # 0 <city name>
  121. # 1 <county FIPS code> <county name>
  122. # 2 <state/province abbreviation> <state/province name>
  123. # 3 <nation abbreviation> <nation name>
  124. # A <telephone area code>
  125. # E <elevation in feet above mean sea level>
  126. # F <feature code> <feature name>
  127. # L <latitude DD MM SS X> <longitude DDD MM SS X>
  128. # P <1980 census population>
  129. # R <remark>
  130. # T <time zone>
  131. # Z <postal ("ZIP") code>
  132.  
  133. # Example
  134. # 0 Ithaca
  135. # 1 36109 Tompkins
  136. # 2 NY New York
  137. # 3 US United States
  138. # R county seat
  139. # F 45 Populated place
  140. # L 42 26 26 N  76 29 49 W
  141. # P 28732
  142. # E 814
  143. # Z 14850 14851 14852 14853 14882
  144. # .
  145.  
  146.